using CardPlay.Model.CardModel;
using CardPlay.Model.GameModel;
using CardPlay.Model.GameModel.Actions;
using CardPlay.Model.GameModel.Presentation;
using CardPlay.Model.Layout;
using CardPlay.Model.Primitives;

namespace CardPlay.DemoPack.Games.SlyFoxVariants
{
    [Game("E0DDC4B6-77A6-484B-8637-992F1D00A321", LevelOfDifficulty.Easy, LevelOfSkill.ModerateSkill, DurationOfPlay.MoreThan10Minutes, NumberOfDecks = 2, Family = FamilyName)]
    public class Grandfather : TwentyBase
    {
        public Grandfather()
        {
            MaximumDeals = 2;
            CardsPerDeal = 1;
        }

        protected override void PrepareStockPresentation(IPresentationContext presentation, SideBySideLayout stockWasteColumn)
        {
            stockWasteColumn.Add(presentation.CreatePileVisual(Stock, presentation.StyleForStock(this)));
            stockWasteColumn.Add(presentation.CreatePileVisual(Waste, presentation.StyleForWaste()));
        }

        protected override void PrepareTableauPresentation(IPresentationContext presentation, CompositeLayout tableau)
        {
            var tableauStyle = new VisualTraits
            {
                Arrangement = (pile, metrics) => CardArrangement.GetStackedCardPlacement(pile, new Size(0, metrics.StackingOffsetOnFaceDownCard.Height * 2), Size.Empty),
                EmptyCue = () => EmptyPileCue.CardSite,
                ContentFit = ContentFit.FitBounds,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Top,
                MinimumSize = presentation.Metrics.CardSize + new Size(presentation.Metrics.MinSpacingAcross, presentation.Metrics.MaxSpacingDown)
            };

            presentation.AddPiles(tableau, NamesOfTableaus, tableauStyle);
        }

        protected override void PrepareDealScript(DealScript script)
        {
            script.DealToEach(NamesOfTableaus, "up");
            script.DealRemainingFaceDownTo(Stock);
        }

        protected override bool AllowedToPickupAtTableau(RemovePileAction action)
        {
            return action.IsActingOnFaceUpTopCard();
        }

        protected override bool AllowedToBuildNonEmptyTableau(MovePileAction action)
        {
            return action.TargetPile.Count < 2 && action.SourcePile.Location.Matches(Waste);
        }

        protected override bool AllowedToBuildEmptyTableau(MovePileAction action)
        {
            return false;
        }

        protected override void OnTransactionEnding()
        {
            this.FillFromStockEmptyPilesMatching(AnyTableau);
        }
    }
}